/*
 * Copyright 2011 Angel Sanadinov
 *
 * This file is part of VBox WMI.
 *
 * VBox WMI is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * VBox WMI is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with VBox WMI.  If not, see <http://www.gnu.org/licenses/>.
 */

package Beans.Requests.MachineManagement;

import Utilities.PermissionsConstants;

/**
 * Instances of this class are used by the user interface when a request to
 * remove a virtual machine is sent to the machines management service.
 *
 * @author Angel Sanadinov
 */
public class RemoveMachineRequest extends MachineManagementRequest
{
    private boolean forceRemoval; //denotes whether the machine should be forcibly removed

    /**
     * No-argument constructor. <br><br>
     * All fields are set to their invalid values.
     */
    public RemoveMachineRequest()
    {
        super();
        this.forceRemoval = false;
        setRequestedAction(PermissionsConstants.ACTION_MACHINE_REMOVE);
    }

    /**
     * Constructs a request for removing a virtual machine.
     *
     * @param requestorId the id of the user that made the request
     * @param serverId the id of the server on which the machine resides
     * @param machineId the id of the virtual machine
     * @param forceRemoval if set to <code>true</code>, all attached media will be detached
     *                     before removal
     */
    public RemoveMachineRequest(int requestorId, int serverId, String machineId, boolean forceRemoval)
    {
        setRequestorId(requestorId);
        setServerId(serverId);
        setMachineId(machineId);
        setRequestedAction(PermissionsConstants.ACTION_MACHINE_REMOVE);
        this.forceRemoval = forceRemoval;
    }

    /**
     * Retrieves the force removal state.
     *
     * @return <code>true</code> if the machine should be forcibly removed or
     *         <code>false</code> otherwise
     */
    public boolean getForceRemoval()
    {
        return forceRemoval;
    }

    /**
     * Sets the force removal state. <br><br>
     *
     * If it is set to <code>true</code>, the machine will have all of its media
     * detached before the removal. Not doing this will usually result in an error
     * from VirtualBox.
     *
     * @param forceRemoval
     */
    public void setForceRemoval(boolean forceRemoval)
    {
        this.forceRemoval = forceRemoval;
    }

    @Override
    public boolean isValid()
    {
        if(super.isValid() && isMachineIdValid())
            return true;
        else
            return false;
    }

    /**
     * Returns a textual representation of the object. <br>
     *
     * It is in the form: "ClassName: (machineId,forceRemoval)".
     *
     * @return the object represented as a String
     */
    @Override
    public String toString()
    {
        return RemoveMachineRequest.class.getSimpleName()
                + ": (" + getMachineId() + "," + forceRemoval + ")";
    }
}
